package drp.snowbell.io;

import java.net.URI;
import java.net.URISyntaxException;

import drp.snowbell.exception.CatchException;


/**
 * 资源管理
 * 
 * @author wuhj
 * 
 */
public class ResourceCenter {
	public final static String FILE_SCHEME = "file";
	public final static String DATABASE_SCHEME = "db";
	public final static String ZIP_SCHEME = "zip";

	public static IResource getResource(String strUri) {
		IResource ret = null;
		try {
			URI uri = new URI(strUri);
			ret = getResource(uri);
		} catch (URISyntaxException e) {
			CatchException.take(e);
		}
		return ret;
	}

	public static IResource getResource(URI uri) {
		IResource ret = null;
		String scheme = uri.getScheme();
		if (DATABASE_SCHEME.equals(scheme)) {
			ret = new DbResource(uri);
		} else if (ZIP_SCHEME.equals(scheme)) {
			ret = new ZIPResource(uri);
		} else {
			ret = new FileResource(uri);
		}
		return ret;
	}
}
